<template>
  <div class="home-container">
    <!-- 轮播图 -->
    <div class="banner-section">
      <el-carousel height="400px">
        <el-carousel-item v-for="(item, index) in bannerItems" :key="index">
          <div class="banner-item" :style="{ backgroundImage: `url(${item.image})` }">
            <div class="banner-content">
              <h2>{{ item.title }}</h2>
              <p>{{ item.description }}</p>
              <el-button type="primary" size="large" @click="navigateTo(item.link)">
                {{ item.buttonText }}
              </el-button>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <!-- 搜索区域 -->
    <div class="search-section">
      <div class="search-container">
        <h2>找到您需要的投标资料</h2>
        <div class="search-box">
          <el-input
            v-model="searchKeyword"
            placeholder="输入关键词搜索资料"
            class="search-input"
            prefix-icon="Search"
          >
          </el-input>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
        </div>
        <div class="hot-keywords">
          <span>热门搜索：</span>
          <el-tag
            v-for="(keyword, index) in hotKeywords"
            :key="index"
            @click="searchByKeyword(keyword)"
            class="hot-keyword-tag"
          >
            {{ keyword }}
          </el-tag>
        </div>
      </div>
    </div>

    <!-- 资料分类 -->
    <div class="category-section">
      <h2 class="section-title">资料分类</h2>
      <div class="category-list">
        <div
          v-for="(category, index) in categories"
          :key="index"
          class="category-item"
          @click="navigateToCategory(category.id)"
        >
          <div class="category-icon">
            <el-icon :size="40"><component :is="category.icon" /></el-icon>
          </div>
          <h3>{{ category.name }}</h3>
          <p>{{ category.count }}个资料</p>
        </div>
      </div>
    </div>

    <!-- 热门资料 -->
    <div class="hot-materials-section">
      <h2 class="section-title">热门资料</h2>
      <el-row :gutter="20">
        <el-col
          v-for="(material, index) in hotMaterials"
          :key="index"
          :xs="24"
          :sm="12"
          :md="8"
          :lg="6"
        >
          <el-card class="material-card" shadow="hover">
            <div class="material-thumbnail">
              <img :src="material.thumbnail" :alt="material.title" />
              <div class="material-price">{{ material.price }} 虚拟币</div>
            </div>
            <div class="material-info">
              <h3 class="material-title" @click="navigateToMaterial(material.id)">
                {{ material.title }}
              </h3>
              <div class="material-meta">
                <span class="material-category">{{ material.category }}</span>
                <span class="material-downloads">
                  <el-icon><Download /></el-icon> {{ material.downloads }}
                </span>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <div class="view-more">
        <el-button type="primary" plain @click="navigateTo('/materials')">
          查看更多资料
        </el-button>
      </div>
    </div>

    <!-- 网站介绍 -->
    <div class="about-section">
      <h2 class="section-title">关于标王资料网</h2>
      <div class="about-content">
        <div class="about-text">
          <p>标王资料网是专业的投标资料下载平台，提供各类高质量的投标文件、标书模板、招标文件等资料。</p>
          <p>我们的资料覆盖建筑工程、IT招标、政府采购等多个领域，帮助您提高投标成功率。</p>
          <el-button type="primary" @click="navigateTo('/about')">了解更多</el-button>
        </div>
        <div class="about-features">
          <div class="feature-item">
            <el-icon :size="40"><Document /></el-icon>
            <h3>海量资源</h3>
            <p>上万份精选投标资料</p>
          </div>
          <div class="feature-item">
            <el-icon :size="40"><RefreshRight /></el-icon>
            <h3>实时更新</h3>
            <p>每日更新最新资料</p>
          </div>
          <div class="feature-item">
            <el-icon :size="40"><Download /></el-icon>
            <h3>便捷下载</h3>
            <p>快速下载无限制</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  Search,
  Download,
  Document,
  RefreshRight,
  Folder,
  OfficeBuilding,
  Monitor,
  School,
  ShoppingBag
} from '@element-plus/icons-vue'

const router = useRouter()
const searchKeyword = ref('')

// 轮播图数据
const bannerItems = [
  {
    title: '专业投标资料下载平台',
    description: '海量投标文件模板，助您提高中标率',
    image: '/images/banner1.jpg',
    link: '/materials',
    buttonText: '立即查看'
  },
  {
    title: '最新投标资料',
    description: '2024年最新投标文件，实时更新',
    image: '/images/banner2.jpg',
    link: '/materials?tag=最新',
    buttonText: '查看最新'
  },
  {
    title: '会员特权',
    description: '成为VIP会员，享受更多下载特权',
    image: '/images/banner3.jpg',
    link: '/vip',
    buttonText: '了解详情'
  }
]

// 热门搜索关键词
const hotKeywords = ['建筑工程', '政府采购', 'IT招标', '设备采购', '服务外包']

// 资料分类
const categories = [
  { id: 1, name: '建筑工程', icon: 'OfficeBuilding', count: 1256 },
  { id: 2, name: 'IT招标', icon: 'Monitor', count: 853 },
  { id: 3, name: '政府采购', icon: 'School', count: 742 },
  { id: 4, name: '设备采购', icon: 'ShoppingBag', count: 635 },
  { id: 5, name: '服务外包', icon: 'Document', count: 521 },
  { id: 6, name: '其他分类', icon: 'Folder', count: 328 }
]

// 热门资料
const hotMaterials = [
  {
    id: 1,
    title: '2024年政府采购标书模板',
    thumbnail: '/images/thumbnail1.jpg',
    price: 5,
    category: '政府采购',
    downloads: 1256
  },
  {
    id: 2,
    title: '建筑工程投标书范本',
    thumbnail: '/images/thumbnail2.jpg',
    price: 8,
    category: '建筑工程',
    downloads: 986
  },
  {
    id: 3,
    title: 'IT系统集成招标文件',
    thumbnail: '/images/thumbnail3.jpg',
    price: 10,
    category: 'IT招标',
    downloads: 753
  },
  {
    id: 4,
    title: '医疗设备采购标书模板',
    thumbnail: '/images/thumbnail4.jpg',
    price: 6,
    category: '设备采购',
    downloads: 642
  }
]

// 搜索处理
const handleSearch = () => {
  if (!searchKeyword.value.trim()) return
  router.push({
    path: '/materials',
    query: { keyword: searchKeyword.value }
  })
}

// 按关键词搜索
const searchByKeyword = (keyword) => {
  searchKeyword.value = keyword
  handleSearch()
}

// 导航到指定路径
const navigateTo = (path) => {
  router.push(path)
}

// 导航到分类页面
const navigateToCategory = (categoryId) => {
  router.push({
    path: '/materials',
    query: { category: categoryId }
  })
}

// 导航到资料详情页
const navigateToMaterial = (materialId) => {
  router.push(`/material/${materialId}`)
}
</script>

<style scoped>
.home-container {
  padding-bottom: 3rem;
}

/* 轮播图样式 */
.banner-section {
  margin-bottom: 3rem;
}

.banner-item {
  height: 100%;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  padding: 0 10%;
}

.banner-content {
  max-width: 600px;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.banner-content h2 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.banner-content p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

/* 搜索区域样式 */
.search-section {
  background-color: #f5f7fa;
  padding: 3rem 0;
  margin-bottom: 3rem;
}

.search-container {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}

.search-container h2 {
  margin-bottom: 2rem;
  color: #303133;
}

.search-box {
  display: flex;
  margin-bottom: 1rem;
}

.search-input {
  flex: 1;
}

.hot-keywords {
  margin-top: 1rem;
  color: #606266;
}

.hot-keyword-tag {
  margin: 0 0.5rem;
  cursor: pointer;
}

/* 分类区域样式 */
.category-section {
  margin-bottom: 3rem;
}

.section-title {
  text-align: center;
  margin-bottom: 2rem;
  color: #303133;
  position: relative;
}

.section-title::after {
  content: '';
  display: block;
  width: 50px;
  height: 3px;
  background-color: #409EFF;
  margin: 0.5rem auto;
}

.category-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.5rem;
}

.category-item {
  background-color: #f5f7fa;
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  transition: all 0.3s;
  cursor: pointer;
}

.category-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.category-icon {
  margin-bottom: 1rem;
  color: #409EFF;
}

.category-item h3 {
  margin: 0.5rem 0;
  color: #303133;
}

.category-item p {
  color: #909399;
  font-size: 0.9rem;
}

/* 热门资料样式 */
.hot-materials-section {
  margin-bottom: 3rem;
}

.material-card {
  margin-bottom: 1.5rem;
  transition: all 0.3s;
}

.material-card:hover {
  transform: translateY(-5px);
}

.material-thumbnail {
  position: relative;
  height: 150px;
  overflow: hidden;
}

.material-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.material-price {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: rgba(64, 158, 255, 0.9);
  color: white;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-weight: bold;
}

.material-info {
  padding: 1rem 0;
}

.material-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-title:hover {
  color: #409EFF;
}

.material-meta {
  display: flex;
  justify-content: space-between;
  color: #909399;
  font-size: 0.9rem;
}

.material-downloads {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.view-more {
  text-align: center;
  margin-top: 2rem;
}

/* 关于我们样式 */
.about-section {
  background-color: #f5f7fa;
  padding: 3rem 0;
}

.about-content {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: center;
}

.about-text {
  flex: 1;
  min-width: 300px;
}

.about-text p {
  margin-bottom: 1rem;
  color: #606266;
  line-height: 1.6;
}

.about-features {
  flex: 1;
  min-width: 300px;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.feature-item {
  flex: 1;
  min-width: 150px;
  text-align: center;
  padding: 1.5rem;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.feature-item .el-icon {
  color: #409EFF;
  margin-bottom: 1rem;
}

.feature-item h3 {
  margin: 0.5rem 0;
  color: #303133;
}

.feature-item p {
  color: #909399;
  font-size: 0.9rem;
}
</style>